package nl.grol.yakshop.binding;

import nl.grol.yakshop.dataimporter.HerdImporterI;
import nl.grol.yakshop.dataimporter.XmlHerdImporter;
import nl.grol.yakshop.domain.repository.Repository;
import nl.grol.yakshop.domain.repository.RepositoryI;
import nl.grol.yakshop.domain.service.BruteForceProducionCalculator;
import nl.grol.yakshop.domain.service.OrderProcessor;
import nl.grol.yakshop.domain.service.OrderProcessorI;
import nl.grol.yakshop.domain.service.ProductionCalculatorI;
import nl.grol.yakshop.domain.service.StockCalculator;
import nl.grol.yakshop.domain.service.StockCalculatorI;
import nl.grol.yakshop.web.filter.RequestEnrichingFilter;
import nl.grol.yakshop.web.servlet.HerdServlet;
import nl.grol.yakshop.web.servlet.ImportServlet;
import nl.grol.yakshop.web.servlet.OrderServlet;
import nl.grol.yakshop.web.servlet.StockServlet;

import com.google.inject.servlet.ServletModule;


public class MyYakShopModule extends ServletModule {

	@Override
	protected void configureServlets() {

		/*
		 * Inject implementations
		 */
	    bind(RepositoryI.class).to(Repository.class);
	    bind(HerdImporterI.class).to(XmlHerdImporter.class);
	    bind(ProductionCalculatorI.class).to(BruteForceProducionCalculator.class);
	    bind(OrderProcessorI.class).to(OrderProcessor.class);
	    bind(StockCalculatorI.class).to(StockCalculator.class);

		/*
		 * Inject PersistanceManager into request context
		 */
		filter("/yak-shop/*").through(RequestEnrichingFilter.class);

		/*
		 * Configure servlets
		 */
	    serve("/yak-shop/import").with(ImportServlet.class);
	    serve("/yak-shop/stock/*").with(StockServlet.class);
	    serve("/yak-shop/herd/*").with(HerdServlet.class);
	    serve("/yak-shop/order/*").with(OrderServlet.class);

	  }

}
